package com.jweb.framework.http.support;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ThemeResolver;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import org.springframework.web.servlet.support.RequestContextUtils;
/**
 * 修改人： Thomas
 * 修改内容：新增 
 * 类说明：Theme转换拦截
 */
public class ThemeChangeInterceptor extends HandlerInterceptorAdapter{
	
	public static final String DEFAULT_PARAM_NAME = "theme";
	
	private String paramName = "theme";

	public String getParamName() {
		return paramName;
	}

	public void setParamName(String paramName) {
		this.paramName = paramName;
	}

	@Override
	public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
		
		ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(request); //"themeResolver"=SmartThemeResolver
		if(themeResolver == null){
			throw new IllegalStateException("No ThemeResolver found: not in a MainServlet request ?");
		}
		String str = request.getParameter(this.paramName); // str=null
		if(str!=null){
			themeResolver.setThemeName(request, response, str);
		}
		
		return true;
	}
	
	

}
